package ai;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class TestAIGraph {

	static String fileName = "aiP1_input.txt";
	static File file = new File(fileName);	

	static List<String> vertices = new ArrayList<String>();
	static List<WeightedEdge> edges = new ArrayList<WeightedEdge>();

	public static void processLine(String line) {

		Scanner scanner = new Scanner(line);
		scanner.useDelimiter("-");

		String startCity = scanner.next().trim();
		String endCity = scanner.next().trim();
		String distance = scanner.next().trim();

		int startNodeLocation = vertices.indexOf(startCity);
		int endNodeLocation = vertices.indexOf(endCity);

		if (startNodeLocation == -1) {
			// System.out.println("Start city of: " + startCity + " not in list.");
			vertices.add(startCity);
			startNodeLocation = vertices.indexOf(startCity);
		}
		if (endNodeLocation == -1) {
			// System.out.println("End city of: " + endCity + " not in list.");
			vertices.add(endCity);
			endNodeLocation = vertices.indexOf(endCity);
		}

		edges.add(new WeightedEdge(startNodeLocation,
				endNodeLocation, Integer.parseInt(distance)));
	}

	public static void main(String[] args) throws FileNotFoundException { 

		Scanner scanner = new Scanner(file);

		while (scanner.hasNext()) {
			processLine(scanner.nextLine());
		}
		
		AIGraph<String> aiGraph = new AIGraph<String>(edges, vertices);
		System.out.println("aiGraph size: " + aiGraph.getSize());
		String path = aiGraph.AIdfs("Knoxville", "Augusta");
		System.out.println("DFS Path:");
		System.out.println(path);
		path = aiGraph.AIbfs("Knoxville", "Augusta");
		System.out.println("BFS Path: ");
		System.out.println(path);
	}
}